package com.example.icongyou.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.icongyou.R;

public class  StudentMainActivity extends AppCompatActivity {

    private TextView tvTotalCourses;
    private TextView tvCompletedTasks;
    private TextView tvAverageScore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_student_main);

        // 处理系统栏间距
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initViews();
        setupClickListeners();
        loadStudentData();
    }

    private void initViews() {
        tvTotalCourses = findViewById(R.id.tv_total_courses);
        tvCompletedTasks = findViewById(R.id.tv_completed_tasks);
        tvAverageScore = findViewById(R.id.tv_average_score);
    }

    private void setupClickListeners() {
        // 课程列表入口
        findViewById(R.id.btn_course_list).setOnClickListener(v -> {
            Intent intent = new Intent(StudentMainActivity.this, CourseListActivity.class);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });

        // 任务中心入口（暂未实现）
        findViewById(R.id.btn_task_center).setOnClickListener(v -> {
            // 后续实现任务中心页面
        });

        // 个人数据看板入口
        findViewById(R.id.btn_personal_dashboard).setOnClickListener(v -> {
            Intent intent = new Intent(StudentMainActivity.this, DashboardActivity.class);
            // 传递参数：默认选中"个人看板"标签（0表示第一个标签）
            intent.putExtra("default_tab", 0);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });

        // 团队数据看板入口
        findViewById(R.id.btn_team_dashboard).setOnClickListener(v -> {
            Intent intent = new Intent(StudentMainActivity.this, DashboardActivity.class);
            // 传递参数：默认选中"团队看板"标签（1表示第二个标签）
            intent.putExtra("default_tab", 1);
            startActivity(intent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });
    }

    private void loadStudentData() {
        // 模拟加载学生数据
        tvTotalCourses.setText(getString(R.string.total_courses));
        tvCompletedTasks.setText(getString(R.string.completed_tasks));
        tvAverageScore.setText(getString(R.string.average_score));
    }
}